import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/recipe/data/api/recipe_detail_info_api.dart';
import 'package:casdon/modules/recipe/data/repository/recipe_repository.dart';
import 'package:casdon/modules/recipe/providers/recipe_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class RecipeDetailInfoUsecase {
  final RecipeRepository _repository;

  const RecipeDetailInfoUsecase(this._repository);

  Future<ResponseRecipeDetailApi?> execute({required String recipeId}) async {
    try {
      var ret = await _repository.getRecipeDetailInfo(recipeId);
      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("RecipeDetailInfoUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("RecipeDetailInfoUsecase 失败");
    }
  }
}

final recipeDetailInfoUsecaseProvider = Provider<RecipeDetailInfoUsecase>((
  ref,
) {
  return RecipeDetailInfoUsecase(ref.read(recipeRepository));
});
